<template>
    <div class="mui-numbox" data-numbox-min="1" :data-numbox-max="max">
      <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
      <input id="test" class="mui-input-numbox" type="number" value="1" @change="countChanged" ref="num"/>
      <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
    </div>
</template>
<script>
import mui from '../../lib/mui/js/mui.min.js'
export default {
    mounted(){
        mui(".mui-numbox").numbox();
    },
    methods:{
        countChanged(){
            this.$emit("getcount",parseInt(this.$refs.num.value))
        }
    },
    props:["max"],
    watch:{
        //因为父组件是异步获得goodsInfo的值，所有有可能子组件元素渲染好，父组件的还没渲染，数据还没获取，导致goodsInfo.stock_quantity为undefined
        max : function(newVal,oldVal){
            // mui自带api设置numbox最大值的方法
            mui(".mui-numbox").numbox().setOption("max",newVal);
        }
    }
};
</script>
<style lang="scss" scoped>
</style>